package com.chuck.service.impl;

import com.chuck.dao.SysMenuMapper;
import com.chuck.entity.SysMenu;
import com.chuck.service.SysMenuService;
import com.chuck.utils.DataGridResult;
import com.chuck.utils.Query;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
@Service
public class sysMenuServiceImpl implements SysMenuService {

    @Autowired
    private SysMenuMapper sysMenuMapper;

    @Override
    public List<SysMenu> queryListAll() {
        return sysMenuMapper.queryListAll();
    }

    @Override
    public DataGridResult getPageList(Query query) {
        List<SysMenu> rows = sysMenuMapper.queryList(query);
        int total = sysMenuMapper.queryTotal();

        DataGridResult dataGridResult = new DataGridResult(rows, total);
        return dataGridResult;
    }
    /*第四步：实现出来*/
    @Override
    //propagation = Propagation.REQUIRED
    //如果当前没有事务就开启一个事务，如果当前有事务就接着当前事务进行
    @Transactional(propagation = Propagation.REQUIRED)
    public void deleteBatch(Long[] menuIds) {
        /*调用他父类的方法*/
        sysMenuMapper.deleteBatch(menuIds);
    }

    @Override
    public List<SysMenu> queryNoButtonList() {
        return sysMenuMapper.queryNoButtonList();
    }

    @Override
    @Transactional(propagation = Propagation.REQUIRED)
    public void save(SysMenu sysMenu) {
        sysMenuMapper.insertSelective(sysMenu);
    }

    @Override
    public SysMenu queryObject(Long menuId) {
        return sysMenuMapper.selectByPrimaryKey(menuId);
    }

    @Override
    @Transactional(propagation = Propagation.REQUIRED)
    public void update(SysMenu sysMenu) {
        sysMenuMapper.updateByPrimaryKeySelective(sysMenu);
    }

}
